package com.xue.web.controller;

import com.alibaba.fastjson.JSONObject;
import com.xue.web.service.RegisterService;
import com.xue.web.utils.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RegisterController {
    public JSONObject starRegister(HttpServletRequest req, HttpServletResponse resp) {
        System.out.println(this.getClass().getSimpleName()+"|校验用户输入信息");
        JSONObject jsonObject = new JSONObject();

        String userName = req.getParameter("userName");
        String userPassword = req.getParameter("userPassword");
        String userEmail = req.getParameter("userEmail");

        {//校验区
            if (StringUtils.isEmpty(userName)) {
                jsonObject.put("code", 400);
                jsonObject.put("msg", "用户名还没输入");
                return jsonObject;
            }
            if (StringUtils.isEmpty(userPassword)) {
                jsonObject.put("code", 400);
                jsonObject.put("msg", "密码还没输入");
                return jsonObject;
            }
            if (StringUtils.isEmpty(userEmail)) {
                jsonObject.put("code", 400);
                jsonObject.put("msg", "邮箱还没输入");
                return jsonObject;
            }
            System.out.println(this.getClass().getSimpleName()+"|校验成功执行注册业务");
        }//校验区

        RegisterService registerService =new RegisterService();
        jsonObject = registerService.doRegister(userName,userPassword,userEmail);

        return jsonObject;
    }
}
